/*
 * Este nombre de clase no es muy feliz, ver cual conviene usar 
 * File:   ControllerSDL.cpp
 * Author: agustin
 * 
 * Created on 22 de mayo de 2014, 10:55
 */

#include "client_ControllerSDL.h"
#include "client_InitializationException.h"
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_ttf.h>

ControllerSDL::ControllerSDL() {
    if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        throw InitializationException(SDL_GetError());
    }

    if (!IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG)) {
        throw InitializationException(IMG_GetError());
    }
    if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) {
        std::cout << "Warning: Linear texture filtering not enabled!" << std::endl;
    }
    //Initialize SDL_ttf
    if (TTF_Init() < 0) {
        throw InitializationException(TTF_GetError());
    }

    //Initialize SDL_mixer
    if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
        throw InitializationException(Mix_GetError());
    }
}

ControllerSDL::~ControllerSDL() {
    //Quit SDL subsystems
    SDL_Quit();
    IMG_Quit();
    TTF_Quit();
    Mix_CloseAudio();
}
